// OtaActiveManager.java
package com.cs.deviceManager.mqtt.ota.manager;

import com.cs.deviceManager.mqtt.ota.FirmwareUpdater;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 管理当前活跃的 OTA 任务
 */
@Component
public class OtaActiveManager {

    private final Map<String, FirmwareUpdater> activeUpdaters = new ConcurrentHashMap<>();

    /**
     * 设置当前设备的 OTA 任务
     */
    public void setActiveUpdater(String deviceId, FirmwareUpdater updater) {
        activeUpdaters.put(deviceId, updater);
    }

    /**
     * 获取当前设备的 OTA 任务
     */
    public FirmwareUpdater getActiveUpdater(String deviceId) {
        return activeUpdaters.get(deviceId);
    }

    /**
     * 移除 OTA 任务
     */
    public void removeActiveUpdater(String deviceId) {
        activeUpdaters.remove(deviceId);
    }
}